home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / ODF / OS / FWMenu / FWMnuItm.cpp < prev    next >
Encoding:
Text File  |  1996-09-17  |  22.6 KB  |  715 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWMnuItm.cpp
  4. //    Release Version:    $ ODF 2 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "FWOS.hpp"
  11.  
  12. #ifndef FWMNUITM_H
  13. #include "FWMnuItm.h"
  14. #endif
  15.  
  16. #ifndef FWMENUS_K
  17. #include "FWMenus.k"
  18. #endif
  19.  
  20. #ifndef FWPULLDM_H
  21. #include "FWPullDM.h"
  22. #endif
  23.  
  24. #ifndef FWMNUBAR_H
  25. #include "FWMnuBar.h"
  26. #endif
  27.  
  28. // ----- Foundation Includes -----
  29.  
  30. #ifndef FWSTREAM_H
  31. #include "FWStream.h"
  32. #endif
  33.  
  34. #ifndef FWSTRING_H
  35. #include "FWString.h"
  36. #endif
  37.  
  38. // ----- OpenDoc Utility Includes -----
  39.  
  40. #ifndef _ITEXT_
  41. #include "IText.h"
  42. #endif
  43.  
  44. // ----- OpenDoc Includes -----
  45.  
  46. #ifndef SOM_ODMenuBar_xh
  47. #include <MenuBar.xh>
  48. #endif
  49.  
  50. // ----- Macintosh Includes -----
  51.  
  52. #if defined(FW_BUILD_MAC) && !defined(__SCRIPT__)
  53. #include <Script.h>
  54. #endif
  55.  
  56. //========================================================================================
  57. // File scope definitions
  58. //========================================================================================
  59.  
  60. #ifdef FW_BUILD_MAC
  61. #pragma segment fwmenu
  62. #endif
  63.  
  64. //========================================================================================
  65. //    Template Instantiations
  66. //========================================================================================
  67.  
  68. FW_DEFINE_AUTO_TEMPLATE(FW_TOrderedCollectionIterator, FW_CMenuItem)
  69. FW_DEFINE_AUTO_TEMPLATE(FW_TOrderedCollection, FW_CMenuItem)
  70.  
  71. #ifdef FW_USE_TEMPLATE_PRAGMAS
  72.  
  73. #pragma template_access public
  74. #pragma template FW_TOrderedCollection<FW_CMenuItem>
  75. #pragma template FW_TOrderedCollectionIterator<FW_CMenuItem>
  76.  
  77. #endif
  78.  
  79. //========================================================================================
  80. //    class FW_CMenuItem
  81. //========================================================================================
  82.  
  83. FW_DEFINE_AUTO(FW_CMenuItem)
  84. FW_DEFINE_CLASS_M0(FW_CMenuItem)
  85.  
  86. // This class is archivable, but we provide the archiving implementation in a separate
  87. // translation unit in order to enable deadstripping of the archiving-related code
  88. // in parts that do not use archiving with this class.
  89.  
  90. //----------------------------------------------------------------------------------------
  91. //    FW_CMenuItem::FW_CMenuItem
  92. //----------------------------------------------------------------------------------------
  93.  
  94. FW_CMenuItem::FW_CMenuItem(Environment* ev, FW_CReadableStream& stream) :
  95.     fOwnerMenu(NULL),
  96.     fIndex(0)
  97. #ifdef FW_BUILD_MAC
  98.     ,fCommandID(FW_kNoCommand)
  99. #endif
  100. {
  101. FW_UNUSED(ev);
  102.     stream >> fIndex;
  103.     FW_READ_DYNAMIC_OBJECT(stream, &fOwnerMenu, FW_CPullDownMenu);
  104.     FW_END_CONSTRUCTOR
  105. }
  106.  
  107. //----------------------------------------------------------------------------------------
  108. //    FW_CMenuItem::FW_CMenuItem
  109. //----------------------------------------------------------------------------------------
  110.  
  111. FW_CMenuItem::FW_CMenuItem(Environment* ev, FW_CPullDownMenu* ownerMenu, short index) :
  112.     fOwnerMenu(ownerMenu), 
  113.     fIndex(index)
  114. #ifdef FW_BUILD_MAC
  115.     ,fCommandID(FW_kNoCommand)
  116. #endif
  117. {
  118. FW_UNUSED(ev);
  119.     FW_ASSERT(ownerMenu != NULL);
  120.     FW_ASSERT(index > 0);
  121.     FW_END_CONSTRUCTOR
  122. }
  123.  
  124. //----------------------------------------------------------------------------------------
  125. //    FW_CMenuItem::~FW_CMenuItem
  126. //----------------------------------------------------------------------------------------
  127.  
  128. FW_CMenuItem::~FW_CMenuItem()
  129. {
  130.     FW_START_DESTRUCTOR
  131. }
  132.  
  133. //----------------------------------------------------------------------------------------
  134. //    FW_CMenuItem::GetCommandID
  135. //----------------------------------------------------------------------------------------
  136.  
  137. ODCommandID FW_CMenuItem::GetCommandID(Environment* ev) const
  138. {
  139. FW_UNUSED(ev);
  140.     FW_ASSERT(fOwnerMenu != NULL);
  141.  
  142. #ifdef FW_BUILD_MAC
  143.     return fCommandID;
  144. #endif
  145.     
  146. #ifdef FW_BUILD_WIN
  147.     return fOwnerMenu->GetCommandID(ev, fIndex);
  148. #endif
  149. }
  150.  
  151. //----------------------------------------------------------------------------------------
  152. //    FW_CMenuItem::PrivGetMenuItem
  153. //----------------------------------------------------------------------------------------
  154.  
  155. FW_CMenuItem* FW_CMenuItem::PrivGetMenuItem(Environment* ev, ODCommandID commandID) const
  156. {
  157. FW_UNUSED(ev);
  158. FW_UNUSED(commandID);
  159.     return NULL;
  160. }
  161.  
  162. //----------------------------------------------------------------------------------------
  163. //    FW_CMenuItem::PrivFindMenuWithID
  164. //----------------------------------------------------------------------------------------
  165.  
  166. FW_CPullDownMenu* FW_CMenuItem::PrivFindMenuWithID(Environment* ev, ODMenuID menuID) const
  167. {
  168. FW_UNUSED(ev);
  169. FW_UNUSED(menuID);
  170.     return NULL;
  171. }
  172.  
  173. //----------------------------------------------------------------------------------------
  174. //    FW_CMenuItem::PrivDisableAll
  175. //----------------------------------------------------------------------------------------
  176.  
  177. void FW_CMenuItem::PrivDisableAll(Environment* ev)
  178. {
  179. FW_UNUSED(ev);
  180.     // Nothing to do on the Mac because FW_CPullDownMenu::DisableAll disables all its items
  181.     // at once
  182.     
  183. #ifdef FW_BUILD_WIN
  184.     HMENU hMenu = fOwnerMenu->GetPlatformMenu(ev).menu;
  185.     ::EnableMenuItem(hMenu, fIndex - 1, MF_BYPOSITION | MF_DISABLED | MF_GRAYED);
  186. #endif
  187. }
  188.  
  189. //----------------------------------------------------------------------------------------
  190. //    FW_CMenuItem::PrivEnableAll
  191. //----------------------------------------------------------------------------------------
  192.  
  193. void FW_CMenuItem::PrivEnableAll(Environment* ev)
  194. {
  195. FW_UNUSED(ev);
  196.     // Nothing to do on the Mac because FW_CPullDownMenu::EnableAll enables all its items
  197.     // at once
  198.     
  199. #ifdef FW_BUILD_WIN
  200.     HMENU hMenu = fOwnerMenu->GetPlatformMenu(ev).menu;
  201.     ::EnableMenuItem(hMenu, fIndex - 1, MF_BYPOSITION | MF_ENABLED);
  202. #endif
  203. }
  204.  
  205. //----------------------------------------------------------------------------------------
  206. //    FW_CMenuItem::PrivAttach
  207. //----------------------------------------------------------------------------------------
  208.  
  209. void FW_CMenuItem::PrivAttach(Environment* ev, FW_CMenuBar* menuBar)
  210. {
  211. FW_UNUSED(ev);
  212. FW_UNUSED(menuBar);
  213.     // Nothing to do 
  214. }
  215.  
  216. //----------------------------------------------------------------------------------------
  217. //    FW_CMenuItem::PrivDetach
  218. //----------------------------------------------------------------------------------------
  219.  
  220. void FW_CMenuItem::PrivDetach(Environment* ev, FW_CMenuBar* menuBar)
  221. {
  222. FW_UNUSED(ev);
  223. FW_UNUSED(menuBar);
  224.     // Nothing to do 
  225. }
  226.  
  227. //----------------------------------------------------------------------------------------
  228. //    FW_CMenuItem::Flatten
  229. //----------------------------------------------------------------------------------------
  230.  
  231. void FW_CMenuItem::Flatten(Environment* ev, FW_CWritableStream& stream)
  232. {
  233. FW_UNUSED(ev);
  234.     FW_WRITE_DYNAMIC_OBJECT(stream, fOwnerMenu, FW_CPullDownMenu);
  235. }
  236.  
  237. //========================================================================================
  238. //    class FW_CSeparatorItem
  239. //========================================================================================
  240.  
  241. FW_DEFINE_AUTO(FW_CSeparatorItem)
  242. FW_DEFINE_CLASS_M1(FW_CSeparatorItem, FW_CMenuItem)
  243.  
  244. // This class is archivable, but we provide the archiving implementation in a separate
  245. // translation unit in order to enable deadstripping of the archiving-related code
  246. // in parts that do not use archiving with this class.
  247.  
  248. //----------------------------------------------------------------------------------------
  249. //    FW_CSeparatorItem::FW_CSeparatorItem
  250. //----------------------------------------------------------------------------------------
  251.  
  252. FW_CSeparatorItem::FW_CSeparatorItem(Environment* ev, FW_CReadableStream& stream) :
  253.     FW_CMenuItem(ev, stream)
  254. {    
  255.     InitSeparator(ev, fOwnerMenu->GetPlatformMenu(ev));
  256.     FW_END_CONSTRUCTOR
  257. }
  258.  
  259. //----------------------------------------------------------------------------------------
  260. //    FW_CSeparatorItem::FW_CSeparatorItem
  261. //----------------------------------------------------------------------------------------
  262.  
  263. FW_CSeparatorItem::FW_CSeparatorItem(Environment* ev, FW_CPullDownMenu* ownerMenu, short index) :
  264.     FW_CMenuItem(ev, ownerMenu, index)
  265. {
  266.     InitSeparator(ev, ownerMenu->GetPlatformMenu(ev));
  267.     FW_END_CONSTRUCTOR
  268. }
  269.  
  270. //----------------------------------------------------------------------------------------
  271. //    FW_CSeparatorItem::~FW_CSeparatorItem
  272. //----------------------------------------------------------------------------------------
  273.  
  274. FW_CSeparatorItem::~FW_CSeparatorItem()
  275. {
  276.     FW_START_DESTRUCTOR
  277. }
  278.  
  279. //----------------------------------------------------------------------------------------
  280. //    FW_CSeparatorItem::InitSeparator
  281. //----------------------------------------------------------------------------------------
  282.  
  283. void FW_CSeparatorItem::InitSeparator(Environment* ev, const ODPlatformMenu& platformMenu)
  284. {
  285. FW_UNUSED(ev);
  286. #ifdef FW_BUILD_MAC
  287.     fCommandID = FW_kSeparatorCommand;
  288.     ::InsertMenuItem(platformMenu, "\p-", fIndex - 1);
  289. #endif
  290.  
  291. #ifdef FW_BUILD_WIN
  292.     ::InsertMenu(platformMenu.menu, fIndex, MF_BYPOSITION | MF_SEPARATOR, 0, NULL);
  293. #endif
  294. }
  295.  
  296. //----------------------------------------------------------------------------------------
  297. //    FW_CSeparatorItem::PrivDisableAll
  298. //----------------------------------------------------------------------------------------
  299.  
  300. void FW_CSeparatorItem::PrivDisableAll(Environment* ev)
  301. {
  302. FW_UNUSED(ev);
  303.     // Nothing to do. Already disabled
  304. }
  305.  
  306. //----------------------------------------------------------------------------------------
  307. //    FW_CSeparatorItem::PrivEnableAll
  308. //----------------------------------------------------------------------------------------
  309.  
  310. void FW_CSeparatorItem::PrivEnableAll(Environment* ev)
  311. {
  312. FW_UNUSED(ev);
  313.     // Should never enable it
  314. }
  315.  
  316. //========================================================================================
  317. //    class FW_CTextItem
  318. //========================================================================================
  319.  
  320. FW_DEFINE_AUTO(FW_CTextItem)
  321. FW_DEFINE_CLASS_M1(FW_CTextItem, FW_CMenuItem)
  322.  
  323. // This class is archivable, but we provide the archiving implementation in a separate
  324. // translation unit in order to enable deadstripping of the archiving-related code
  325. // in parts that do not use archiving with this class.
  326.  
  327. //----------------------------------------------------------------------------------------
  328. //    FW_CTextItem::FW_CTextItem
  329. //----------------------------------------------------------------------------------------
  330.  
  331. FW_CTextItem::FW_CTextItem(Environment* ev, FW_CReadableStream& stream) :
  332.     FW_CMenuItem(ev, stream)
  333. {
  334.     ODCommandID commandID;
  335.     stream >> commandID;
  336.     
  337.     FW_MenuKey menuKey;
  338.     stream >> menuKey;
  339.     
  340.     FW_CString text;
  341.     stream >> text;
  342.     
  343.     PrivInitTextItem(ev, fOwnerMenu->GetPlatformMenu(ev), text, commandID, menuKey);
  344.     FW_END_CONSTRUCTOR
  345. }
  346.  
  347. //----------------------------------------------------------------------------------------
  348. //    FW_CTextItem::FW_CTextItem
  349. //----------------------------------------------------------------------------------------
  350.  
  351. FW_CTextItem::FW_CTextItem(Environment* ev,
  352.                         FW_CPullDownMenu* ownerMenu, 
  353.                         short index,            
  354.                         const FW_CString& text,
  355.                         ODCommandID commandID,
  356.                         FW_MenuKey menuKey) :
  357.     FW_CMenuItem(ev, ownerMenu, index)
  358. {
  359.     FW_ASSERT(commandID > 0);
  360.     PrivInitTextItem(ev, ownerMenu->GetPlatformMenu(ev), text, commandID, menuKey);
  361.     FW_END_CONSTRUCTOR
  362. }
  363.  
  364. //----------------------------------------------------------------------------------------
  365. //    FW_CTextItem::~FW_CTextItem
  366. //----------------------------------------------------------------------------------------
  367.  
  368. FW_CTextItem::~FW_CTextItem()
  369. {
  370.     FW_START_DESTRUCTOR
  371. }
  372.  
  373. //----------------------------------------------------------------------------------------
  374. //    FW_CTextItem::PrivInitTextItem
  375. //----------------------------------------------------------------------------------------
  376.  
  377. void FW_CTextItem::PrivInitTextItem(Environment* ev,
  378.                               const ODPlatformMenu&    platformMenu,
  379.                               const FW_CString& text,
  380.                               ODCommandID commandID,
  381.                               FW_MenuKey menuKey)
  382. {
  383. FW_UNUSED(ev);
  384.     FW_ASSERT(commandID >= FW_kFirstUserCommandID);
  385.     
  386. #ifdef FW_BUILD_MAC
  387.     fCommandID = commandID;
  388.     
  389.     Str255 str;
  390.     text.ExportPascal(str);
  391.     ::InsertMenuItem(platformMenu, "\pabc", fIndex - 1);
  392.     ::SetMenuItemText(platformMenu, fIndex, str);
  393.     
  394.     ODScriptCode systemScriptCode = (ODScriptCode) ::GetScriptManagerVariable(smSysScript);
  395.     FW_Locale locale;
  396.     text.GetLocale(locale);
  397.     if (locale.fScriptCode != systemScriptCode)
  398.     {    // set this menu item's script code
  399.         ::SetItemCmd(platformMenu, fIndex, FW_kPrivMacScriptCodeKeyEquivalent);
  400.         ::SetItemIcon(platformMenu, fIndex, locale.fScriptCode);
  401.         menuKey = FW_kNoKeyEquivalent;    // so that code below doesn't mess up the key field we just set
  402.     }
  403.     
  404.     if (menuKey != FW_kNoKeyEquivalent)
  405.         ::SetItemCmd(platformMenu, fIndex, menuKey & FW_kPrivMacMenuKeyCharMask);
  406. #endif
  407.  
  408. #ifdef FW_BUILD_WIN
  409.     char szText[256];
  410.     text.ExportCString(szText);
  411.     ::InsertMenu(platformMenu.menu, fIndex, MF_BYPOSITION | MF_STRING | MF_DISABLED | MF_UNCHECKED, commandID, szText);
  412.     //::AppendMenu(platformMenu.menu, MF_STRING | MF_DISABLED | MF_UNCHECKED, commandID, text);
  413.     
  414.     // [HLX] No way yet to build accelerator table
  415. FW_UNUSED(menuKey);
  416. #endif
  417. }
  418.  
  419. #ifdef FW_BUILD_MAC
  420. //----------------------------------------------------------------------------------------
  421. //    FW_CTextItem::PrivAttach
  422. //----------------------------------------------------------------------------------------
  423.  
  424. void FW_CTextItem::PrivAttach(Environment* ev, FW_CMenuBar* menuBar)
  425. {
  426.     menuBar->PrivMacRegisterCommand(ev, fCommandID, fOwnerMenu->GetMenuID(ev), fIndex);
  427. }
  428. #endif
  429.  
  430. #ifdef FW_BUILD_MAC
  431. //----------------------------------------------------------------------------------------
  432. //    FW_CTextItem::PrivDetach
  433. //----------------------------------------------------------------------------------------
  434.  
  435. void FW_CTextItem::PrivDetach(Environment* ev, FW_CMenuBar* menuBar)
  436. {
  437.     menuBar->PrivMacUnregisterCommand(ev, fCommandID);
  438. }
  439. #endif
  440.  
  441. //----------------------------------------------------------------------------------------
  442. //    FW_CTextItem::Flatten
  443. //----------------------------------------------------------------------------------------
  444.  
  445. void FW_CTextItem::Flatten(Environment* ev, FW_CWritableStream& stream)
  446. {
  447.     FW_CMenuItem::Flatten(ev, stream);
  448.     
  449.     FW_CMenuBar* menuBar = fOwnerMenu->GetMenuBar(ev);
  450.     
  451.     ODCommandID commandID = GetCommandID(ev);
  452.     stream << commandID;
  453.  
  454.     FW_MenuKey menuKey = menuBar->GetMenuKey(ev, commandID);
  455.     stream << menuKey;
  456.  
  457.     FW_CString text;
  458.     menuBar->GetItemString(ev, commandID, text);
  459.     stream << text;
  460. }
  461.  
  462. //========================================================================================
  463. //    class FW_CToggleItem
  464. //========================================================================================
  465.  
  466. FW_DEFINE_AUTO(FW_CToggleItem)
  467. FW_DEFINE_CLASS_M1(FW_CToggleItem, FW_CTextItem)
  468.  
  469. // This class is archivable, but we provide the archiving implementation in a separate
  470. // translation unit in order to enable deadstripping of the archiving-related code
  471. // in parts that do not use archiving with this class.
  472.  
  473. //----------------------------------------------------------------------------------------
  474. //    FW_CToggleItem::FW_CToggleItem
  475. //----------------------------------------------------------------------------------------
  476.  
  477. FW_CToggleItem::FW_CToggleItem(Environment* ev, FW_CReadableStream& stream) :
  478.     FW_CTextItem(ev, stream),
  479.     fToggleState(true)
  480. {
  481.     stream >> fOtherText;
  482.     FW_END_CONSTRUCTOR
  483. }
  484.  
  485. //----------------------------------------------------------------------------------------
  486. //    FW_CToggleItem::FW_CToggleItem
  487. //----------------------------------------------------------------------------------------
  488.  
  489. FW_CToggleItem::FW_CToggleItem(Environment* ev,
  490.                         FW_CPullDownMenu* ownerMenu, 
  491.                         short index,            
  492.                         const FW_CString& trueText,
  493.                         const FW_CString& falseText,
  494.                         ODCommandID commandID,
  495.                         FW_MenuKey menuKey) :
  496.     FW_CTextItem(ev, ownerMenu, index, trueText, commandID, menuKey),
  497.     fToggleState(true)
  498. {
  499.     fOtherText = falseText;
  500.     FW_END_CONSTRUCTOR
  501. }
  502.  
  503. //----------------------------------------------------------------------------------------
  504. //    FW_CToggleItem::~FW_CToggleItem
  505. //----------------------------------------------------------------------------------------
  506.  
  507. FW_CToggleItem::~FW_CToggleItem()
  508. {
  509.     FW_START_DESTRUCTOR
  510. }
  511.  
  512. //----------------------------------------------------------------------------------------
  513. //    FW_CToggleItem::ToggleItem
  514. //----------------------------------------------------------------------------------------
  515.  
  516. void FW_CToggleItem::ToggleItem(Environment* ev, FW_Boolean newState)
  517. {
  518.     if (newState == fToggleState)
  519.         return;
  520.     
  521.     FW_CMenuBar* menuBar = fOwnerMenu->GetMenuBar(ev);
  522.     
  523.     FW_CString currentText;
  524.     menuBar->GetItemString(ev, GetCommandID(ev), currentText);
  525.         
  526.     fToggleState = newState;
  527.     
  528.     menuBar->SetItemString(ev, GetCommandID(ev), fOtherText);
  529.     
  530.     fOtherText = currentText;
  531. }
  532.  
  533. //----------------------------------------------------------------------------------------
  534. //    FW_CToggleItem::Flatten
  535. //----------------------------------------------------------------------------------------
  536.  
  537. void FW_CToggleItem::Flatten(Environment* ev, FW_CWritableStream& stream)
  538. {
  539.     FW_CTextItem::Flatten(ev, stream);
  540.     
  541.     stream << fOtherText;
  542. }
  543.  
  544. //========================================================================================
  545. //    class FW_CSubMenuItem
  546. //========================================================================================
  547.  
  548. FW_DEFINE_AUTO(FW_CSubMenuItem)
  549. FW_DEFINE_CLASS_M1(FW_CSubMenuItem, FW_CMenuItem)
  550.  
  551. // This class is archivable, but we provide the archiving implementation in a separate
  552. // translation unit in order to enable deadstripping of the archiving-related code
  553. // in parts that do not use archiving with this class.
  554.  
  555. //----------------------------------------------------------------------------------------
  556. //    FW_CSubMenuItem::FW_CSubMenuItem
  557. //----------------------------------------------------------------------------------------
  558.  
  559. FW_CSubMenuItem::FW_CSubMenuItem(Environment* ev, FW_CReadableStream& stream) :
  560.     FW_CMenuItem(ev, stream)
  561. {
  562.     FW_READ_DYNAMIC_OBJECT(stream, &fSubMenu, FW_CPullDownMenu);
  563.     
  564.     PrivInitSubMenu(ev, fOwnerMenu->GetPlatformMenu(ev));
  565.     FW_END_CONSTRUCTOR
  566. }
  567.  
  568. //----------------------------------------------------------------------------------------
  569. //    FW_CSubMenuItem::FW_CSubMenuItem
  570. //----------------------------------------------------------------------------------------
  571.  
  572. FW_CSubMenuItem::FW_CSubMenuItem(Environment* ev,
  573.                 FW_CPullDownMenu* ownerMenu, 
  574.                 short index,
  575.                 FW_CPullDownMenu* adoptSubMenu):
  576.     FW_CMenuItem(ev, ownerMenu, index),
  577.     fSubMenu(adoptSubMenu)
  578. {
  579.     FW_ASSERT(adoptSubMenu != NULL);
  580.     PrivInitSubMenu(ev, ownerMenu->GetPlatformMenu(ev));
  581.     FW_END_CONSTRUCTOR
  582. }
  583.  
  584. //----------------------------------------------------------------------------------------
  585. //    FW_CSubMenuItem::~FW_CSubMenuItem
  586. //----------------------------------------------------------------------------------------
  587.  
  588. FW_CSubMenuItem::~FW_CSubMenuItem()
  589. {
  590.     FW_START_DESTRUCTOR
  591.     delete fSubMenu;
  592.     fSubMenu = NULL;
  593. }
  594.  
  595. //----------------------------------------------------------------------------------------
  596. //    FW_CSubMenuItem::PrivInitSubMenu
  597. //----------------------------------------------------------------------------------------
  598.  
  599. void FW_CSubMenuItem::PrivInitSubMenu(Environment* ev, const ODPlatformMenu& platformMenu)
  600. {
  601.     const ODPlatformMenu& subPlatformMenu = fSubMenu->GetPlatformMenu(ev);
  602.  
  603. #ifdef FW_BUILD_MAC
  604.     fSubMenu->SetParentMenuItem(ev, this);
  605.     
  606.     // ----- Add it -----
  607.     ::InsertMenuItem(platformMenu, "\pabc", fIndex - 1);
  608.         
  609.     ::HLock((Handle)subPlatformMenu);
  610.     ::SetMenuItemText(platformMenu, fIndex, (*subPlatformMenu)->menuData);
  611.     ::HUnlock((Handle)subPlatformMenu);
  612.     
  613.     // ----- Set the cmd key to hMenuCmd to specify sub menu
  614.     ::SetItemCmd(platformMenu, fIndex, hMenuCmd);        // has sub menu
  615.     
  616.     // ----- The menu id of the submenu is in the mark character
  617.     //     We don't set the item mark because we don't know yet the 
  618.     //    ID of the sub menu. Will be done by PrivAttachedToMenuBar.
  619. #endif
  620.  
  621. #ifdef FW_BUILD_WIN
  622.     ::InsertMenu(platformMenu.menu,
  623.                  fIndex,
  624.                  MF_BYPOSITION | MF_POPUP,
  625.                  (UINT) subPlatformMenu.menu,
  626.                  subPlatformMenu.strMenu);
  627. #endif
  628. }
  629.  
  630. //----------------------------------------------------------------------------------------
  631. //    FW_CSubMenuItem::PrivFindMenuWithID
  632. //----------------------------------------------------------------------------------------
  633.  
  634. FW_CPullDownMenu* FW_CSubMenuItem::PrivFindMenuWithID(Environment* ev, ODMenuID menuID) const
  635. {
  636.     if (fSubMenu->GetMenuID(ev) == menuID)
  637.         return fSubMenu;
  638.     else 
  639.         return fSubMenu->PrivFindMenuWithID(ev, menuID);
  640. }
  641.  
  642. //----------------------------------------------------------------------------------------
  643. //    FW_CSubMenuItem::PrivGetMenuItem
  644. //----------------------------------------------------------------------------------------
  645.  
  646. FW_CMenuItem* FW_CSubMenuItem::PrivGetMenuItem(Environment* ev, ODCommandID commandID) const
  647. {
  648.     return fSubMenu->PrivGetMenuItem(ev, commandID);
  649. }
  650.  
  651. //----------------------------------------------------------------------------------------
  652. //    FW_CSubMenuItem::PrivDisableAll
  653. //----------------------------------------------------------------------------------------
  654.  
  655. void FW_CSubMenuItem::PrivDisableAll(Environment* ev)
  656. {
  657. //    FW_CMenuItem::PrivDisableAll(ev);
  658.     
  659.     fSubMenu->DisableAll(ev);
  660. }
  661.  
  662. //----------------------------------------------------------------------------------------
  663. //    FW_CSubMenuItem::PrivEnableAll
  664. //----------------------------------------------------------------------------------------
  665.  
  666. void FW_CSubMenuItem::PrivEnableAll(Environment* ev)
  667. {
  668.     FW_CMenuItem::PrivEnableAll(ev);
  669.     
  670.     fSubMenu->EnableAll(ev);
  671. }
  672.  
  673. //----------------------------------------------------------------------------------------
  674. //    FW_CSubMenuItem::PrivAttach
  675. //----------------------------------------------------------------------------------------
  676.  
  677. void FW_CSubMenuItem::PrivAttach(Environment* ev, FW_CMenuBar* menuBar)
  678. {
  679.     ODMenuID subMenuID = fSubMenu->PrivAcquireMenuID(ev, menuBar);
  680. #ifdef FW_BUILD_MAC
  681.     ::SetItemMark(fOwnerMenu->GetPlatformMenu(ev), fIndex, (FW_Char)subMenuID);
  682. #endif
  683.  
  684.     menuBar->PrivAddSubMenu(ev, subMenuID, fSubMenu->GetPlatformMenu(ev));
  685.     
  686.     fSubMenu->PrivAttach(ev, menuBar);
  687. }
  688.  
  689. //----------------------------------------------------------------------------------------
  690. //    FW_CSubMenuItem::PrivDetach
  691. //----------------------------------------------------------------------------------------
  692.  
  693. void FW_CSubMenuItem::PrivDetach(Environment* ev, FW_CMenuBar* menuBar)
  694. {
  695. #ifdef FW_BUILD_MAC
  696.     ::SetItemMark(fOwnerMenu->GetPlatformMenu(ev), fIndex, (FW_Char)0xFF);
  697. #endif
  698.     menuBar->PrivRemoveMenu(ev, fSubMenu->GetMenuID(ev));
  699.  
  700.     fSubMenu->PrivRelinquishMenuID(ev);
  701.         
  702.     fSubMenu->PrivDetach(ev, menuBar);
  703. }
  704.  
  705. //----------------------------------------------------------------------------------------
  706. //    FW_CSubMenuItem::Flatten
  707. //----------------------------------------------------------------------------------------
  708.  
  709. void FW_CSubMenuItem::Flatten(Environment* ev, FW_CWritableStream& stream)
  710. {
  711.     FW_CMenuItem::Flatten(ev, stream);
  712.     
  713.     FW_WRITE_DYNAMIC_OBJECT(stream, fSubMenu, FW_CPullDownMenu);
  714. }
  715.